package patternmining.model.construction.bpsl;

import java.io.FileInputStream;
import java.io.IOException;
import org.antlr.runtime.ANTLRInputStream;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.RecognitionException;
import org.antlr.runtime.tree.CommonTree;
import patternmining.model.construction.File;

public class BpslFile extends File {

    private java.io.File source;
    private BpslAst ast;

    public BpslFile(java.io.File file){
        source = file;
    }

    public void buildAst(){
        FileInputStream input = null;
        try{
            input = new FileInputStream(source);
            ANTLRInputStream antlrInput = new ANTLRInputStream(input);
            BpslLanguageLexer lexer = new BpslLanguageLexer(antlrInput);
            CommonTokenStream tokens = new CommonTokenStream(lexer);
            BpslLanguageParser parser = new BpslLanguageParser( tokens );
            CommonTree tree = (CommonTree) parser.specification().getTree();
            ast = new BpslAst(tree);
        }
        catch(IOException e){
            e.printStackTrace();
        }
        catch(RecognitionException e){
            e.printStackTrace();
        }
        finally{
            try{
                input.close();
            }
            catch(IOException e){

            }
        }
    }

    public BpslAst getAst(){
        return ast;
    }
	 
}
 
